package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.dto.member.MemberUserAddDto;
import com.zzyl.nursing.dto.member.QueryDeviceDataListByDay;
import com.zzyl.nursing.dto.member.QueryDeviceDataListByWeek;
import com.zzyl.nursing.dto.member.QueryDevicePropertyStatus;
import com.zzyl.nursing.service.MemberUserService;
import com.zzyl.nursing.vo.member.MemberInfo;
import com.zzyl.nursing.vo.member.MemberUserMy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.zzyl.common.core.domain.AjaxResult.success;
import static com.zzyl.common.utils.PageUtils.startPage;

/**
 *小程序端实战
 *@Author zhu
 *@Date 2025/10/29 16:25
 */
@RestController
@RequestMapping("/member/user")
public class MemberUserController extends BaseController {
    @Autowired
    private MemberUserService memberUserService;

    /**
     * 绑定老人
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MemberUserAddDto dto) {
        memberUserService.add(dto);
        return success();
    }

    /**
     * 查询家人列表
     * @return
     */
    @GetMapping("/my")
    public AjaxResult my() {
        List<MemberUserMy> familyMemberElderList = memberUserService.my();
        return AjaxResult.success(familyMemberElderList);
    }

    /**
     * 分页查询
     * @return
     */
    @GetMapping("/list-by-page")
    public AjaxResult list() {
        startPage();
        List<MemberInfo> page = memberUserService.listpage();
        return success(page);
    }

    /**
     * 解绑老人
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById")
    public AjaxResult deletebyid(Integer id) {
        memberUserService.deletebyid(id);
        return success();
    }

    /**
     * 查询健康数据
     * @param dto
     * @return
     */
    @PostMapping("/QueryDevicePropertyStatus")
    public AjaxResult QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatus dto) {

        Map<String, Object> map = memberUserService.QueryDevicePropertyStatus(dto);
        return AjaxResult.success(map);
    }

    /**
     * 按天统计查询指标数据
     * @return
     */
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(QueryDeviceDataListByDay quary) {
        List<Map<String, Object>> list = memberUserService.queryDeviceDataListByDay(quary);
        return AjaxResult.success(list);
    }

    /**
     * 按周统计查询指标数据
     * @param quary
     * @return
     */
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(QueryDeviceDataListByWeek quary) {
        List<Map<String, Object>> list = memberUserService.queryDeviceDataListByWeek(quary);
        return AjaxResult.success(list);
    }
}
